$( document ).ready(function() {
    $('#objectlist').objectlist({
		links: {'fruit': './{id}/fruit/'},
        checked: true,
        columns: [
            ['Fruit', 'fruit',  '100px'],
            ['Weight, kg.', 'weight', '100px'],
            ['Region', 'country', '100px']],
        initialData: [
            {fruit: 'apple', weight: 100, 'country': 'Russia'},
            {fruit: 'banana', weight: 55, 'country': 'India'},
            {fruit: 'orange', weight: 120, 'country': 'Brasil'}],
    });
    
    var object = {fruit: 'strawberry', weight: 70, 'country': 'USA'};

    $('#deselect_all').click(function() {
    	$('#objectlist').objectlist('deselectAll');
    });

    $('#clear').click(function() {
    	$('#objectlist').objectlist('clear');
    });

    $('#blank').click(function() {
    	$('#objectlist').objectlist('blank');
    });

    $('#select_all').click(function() {
    	$('#objectlist').objectlist('selectAll');
    });

    $('#select_object').click(function() {
    	$('#objectlist').objectlist('select', object);
    });

    $('#get_selected').click(function() {
        console.log($('#objectlist').objectlist('getSelected'));
    });

    $('#get').click(function() {
        console.log($('#objectlist').objectlist('get', $('#object_id').val()));
    });
    
    $('#delete').click(function() {
        var objects = $('#objectlist').objectlist('getSelected');
        for ( var i=0; i<objects.length; i++)
        	objects[i].proxy.delete();
    });
    
    $('#add').click(function() {
    	$('#objectlist').objectlist('add', object);
    });

    // console.log(objectlist);
});
